﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.ucPub.Map
{
    public partial class uc_Pub_Map_Select_ListView_ByOne_ForDigitalMap : DevExpress.XtraEditors.XtraForm
    {
        public string _MapID = "-1";
        public uc_Pub_Map_Select_ListView_ByOne_ForDigitalMap()
        {
            InitializeComponent();
        }

        private void uc_Pub_Map_Select_ListView_ByOne_ForDigitalMap_Load(object sender, EventArgs e)
        {
            ArrayList pList = new ArrayList();
            LeverString_SysTreeMainList p = new LeverString_SysTreeMainList();
            string _str = "";
            string _sQueryMapResult = " and (f_level like '%,-1,%'";
            string strSQL = "select f_swid as f_id from TS_S_B_R_Digital_Map_Main_Station where f_del=0 and f_dmid=" + _MapID;
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                _sQueryMapResult += " or f_level like '%," + read["f_id"].ToString() + ",%'";
            }
            _sQueryMapResult += ")";
            strSQL = "select f_id,f_name,f_level from TS_S_B_Station_WorkPlace where f_del=0  and f_id not in (select f_swid from TS_S_B_R_Digital_Map_Main_Element where f_dmmid=" + _MapID + " and f_del=0) " + _sQueryMapResult;
            read.Close();
            comm = new SqlCommand(strSQL, conn);
            read = comm.ExecuteReader();
            while (read.Read())
            {
                p = new LeverString_SysTreeMainList();

                if (read["f_level"].ToString() == ",")
                {
                }
                else
                {
                    _str = read["f_level"].ToString();
                    _str = _str.Substring(0, (_str).Length-1);
                    _str = _str.Substring(_str.LastIndexOf(',') + 1);
                    p.f_parent = _str;
                }
                p.f_name = read["f_name"].ToString();
                p.f_id = read["f_id"].ToString();
                pList.Add(p);
            }
            read.Close();
            conn.Close();
            conn.Dispose();
            tl_Level.DataSource = pList;
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            try
            {
                TS_XY_Train_Repaire.Main_Base.DigitalMap.TS_Main_Base_Digital_Map_Map_Edit _uc = new TS_XY_Train_Repaire.Main_Base.DigitalMap.TS_Main_Base_Digital_Map_Map_Edit();
                TS_XY_Train_Repaire.Main_Base.DigitalMap.TS_Main_Base_Digital_Map_Map_Edit._WorkPlaceID = tl_Level.FocusedNode.GetValue("f_id").ToString();
                TS_XY_Train_Repaire.Main_Base.DigitalMap.TS_Main_Base_Digital_Map_Map_Edit._WorkPlaceName = tl_Level.FocusedNode.GetValue("f_name").ToString();
                //_uc._LoadWorkPlaceName(tl_Level.FocusedNode.GetValue("f_id").ToString(), tl_Level.FocusedNode.GetValue("f_name").ToString());
                this.DialogResult = DialogResult.OK;
            }
            catch
            {
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}